# Project name
PROJECT (scom)

# CMake 2.6 required
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

# Python is required
FIND_PACKAGE(PythonLibs 3)

FIND_PACKAGE(PkgConfig)
PKG_CHECK_MODULES (DBUS REQUIRED dbus-1)

# Application name
SET (APP_NAME "scom")
SET (APP_SUFFIX "3")

# Uncomment this for production releases.
SET (VERSION_SUFFIX "")
#SET (FLAGS "-g -O0 -Wcast-align -Wno-uninitialized -Wall -fstrict-aliasing")

SET (FLAGS "-g -O0 -Wno-uninitialized -Wall -fstrict-aliasing")
# Uncomment this for gprof profiling
# SET (FLAGS "-g -O0 -Werror -Wcast-align -Wno-uninitialized -Wall -fstrict-aliasing -fprofile-arcs -ftest-coverage")
SET (CMAKE_C_FLAGS "${FLAGS}")
# Uncomment this for sparse building
# SET (CMAKE_C_COMPILER cgcc)

# Append name suffix, if specified
IF (APP_SUFFIX)
   SET (APP_NAME "${APP_NAME}${APP_SUFFIX}")
ENDIF (APP_SUFFIX)

# Define version, config dir, data dir and log file.
ADD_DEFINITIONS (
                 -D'PID_FILE="/var/run/${APP_NAME}.pid"'
                 -D'DATA_DIR="/var/lib/${APP_NAME}"'
                 -D'LOG_DIR="/var/log/${APP_NAME}"')

# Set standard sources
SET (SOURCES src/main.c
             src/bus.c
             src/config.c
             src/db.c
             src/iksemel.c
             src/log.c
             src/loop.c
             src/process.c
             src/policy.c
             src/pydbus.c
             src/script.c
             src/utils.c)

# Set standard libraries
SET (LIBS ${PYTHON_LIBRARIES}
          dbus-1)

# Include standard headers
INCLUDE_DIRECTORIES (include/
                     ${PYTHON_INCLUDE_DIRS}
                     ${DBUS_INCLUDE_DIRS})

# Compile scom from specified sources
ADD_EXECUTABLE (scom ${SOURCES})

# Link scom to specified libraries
TARGET_LINK_LIBRARIES(scom ${LIBS} )

# Install scom to /usr/sbin/<app-name>
INSTALL (PROGRAMS scom
         DESTINATION /usr/sbin)

# Install Models
INSTALL (DIRECTORY
        models
        DESTINATION /var/db/${APP_NAME}
        PATTERN ".svn" EXCLUDE)

# Install Modules
INSTALL (DIRECTORY
        modules
        DESTINATION /var/db/${APP_NAME}
        PATTERN ".svn" EXCLUDE)

# Install service activation config under /usr/share/dbus-1/system-services/
INSTALL (FILES
         config/tr.org.sulin.scom.service
         config/tr.org.sulin.scom2.service
         DESTINATION /usr/share/dbus-1/system-services/)

# Install polkit policies
INSTALL (DIRECTORY
         policy/
         DESTINATION /usr/share/polkit-1/actions
         FILES_MATCHING PATTERN "*.policy"
         PATTERN ".svn" EXCLUDE)

# Install system bus policy under /etc/dbus-1/system.d/
INSTALL (FILES
         config/tr.org.sulin.scom.conf
         DESTINATION /etc/dbus-1/system.d)

# Install hav to /usr/bin/hav
INSTALL (PROGRAMS tools/hav.py
         DESTINATION /usr/bin
         RENAME hav)
